// 引入express模块
const express=require('express')
const cors=require('cors')
// 分店路由
const branchRouter=require('./router/branch.js')
//部门路由
const deptRouter=require('./router/dept.js')
//员工路由
const empRouter=require('./router/emp.js')
//房间类型路由
const roomTypeRouter=require('./router/roomType.js')
//上海分店房间的路由
const ShanghaiRouter=require('./router/ShanghaiRoom.js')
//北京分店房间的路由
const BeijingRouter=require('./router/BeijingRoom.js')
//深圳分店房间的路由
const ShenzhenRouter=require('./router/ShenzhenRoom.js')
//广州分店房间的路由
const GuangzhouRouter=require('./router/GuangzhouRoom.js')
//重庆分店房间的路由
const ChongqingRouter=require('./router/ChongqingRoom.js')
//杭州分店房间的路由
const HangzhouRouter=require('./router/HangzhouRoom.js')
//成都分店房间的路由
const ChengduRouter=require('./router/ChengduRoom.js')
//南京分店房间的路由
const NanjingRouter=require('./router/NanjingRoom.js')
//武汉分店房间的路由
const WuhanRouter=require('./router/WuhanRoom.js')
//苏州分店房间的路由
const SuzhouRouter=require('./router/SuzhouRoom.js')
//用户登录的路由
const userLoginRouter= require('./router/userLogin')



// 创建WEB服务器
const app=express()
// 设置端口
app.listen(3000,()=>{
    console.log('服务器启动');
})

//解决跨域
app.use(cors())

//静态资源托管
app.use(express.static('public'))

// 将所有post传参转为对象
app.use(express.urlencoded({
    extended:true
}))


//挂载分店的路由
app.use('/branch',branchRouter)
//挂载部门的路由
app.use('/dept',deptRouter)
//挂载员工的路由
app.use('/emp',empRouter)
//挂载房间类型的路由
app.use('/roomType',roomTypeRouter)
//挂载上海分店房间的路由
app.use('/ShanghaiBranch',ShanghaiRouter)
//挂载北京分店房间的路由
app.use('/BeijingBranch',BeijingRouter)
//挂载深圳分店房间的路由
app.use('/ShenzhenBranch',ShenzhenRouter)
//挂载广州分店房间的路由
app.use('/GuangzhouBranch',GuangzhouRouter)
//挂载重庆分店房间的路由
app.use('/ChongqingBranch',ChongqingRouter)
//挂载杭州分店房间的路由
app.use('/HangzhouBranch',HangzhouRouter)
//挂载成都分店房间的路由
app.use('/ChengduBranch',ChengduRouter)
//挂载南京分店房间的路由
app.use('/NanjingBranch',NanjingRouter)
//挂载武汉分店房间的路由
app.use('/WuhanBranch',WuhanRouter)
//挂载苏州分店房间的路由
app.use('/SuzhouBranch',SuzhouRouter)
//挂载用户登录路由
app.use('/user',userLoginRouter)




//错误处理中间件
app.use((err,req,res,next)=>{
    console.log(err);
    res.send({code:500,msg:'服务器端错误'})
})